<!DOCTYPE HTML>
<html>
	<head>
		<meta charset="utf-8"/>
		<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
		<meta name="HandheldFriendly" content="true"/>
		<meta name="MobileOptimized" content="320"/>
		<title>Hello H5+</title>
		<script type="text/javascript" src="../../js/common.js"></script>
		<script type="text/javascript">
			var img = null;
			var blist = [];
			var preate={};
			var _openw=null;
			
			function clicked(id,a,s){
				if(_openw){return;}
				a||(a=as);
				_openw=preate[id];
				if(_openw){
					_openw.showded=true;
					_openw.show(a,null,function(){
						_openw=null;//避免快速点击打开多个页面
					});
				}else{
			//		var wa=plus.nativeUI.showWaiting();
			//		_openw=plus.webview.create(id,id,{scrollIndicator:'none',scalable:false,popGesture:'hide'},{preate:true});//复用二级页面
					_openw=plus.webview.create(id,id,{scrollIndicator:'none',scalable:false,popGesture:'close'});
					preate[id]=_openw;
					_openw.addEventListener('loaded',function(){//叶面加载完成后才显示
			//		setTimeout(function(){//延后显示可避免低端机上动画时白屏
			//			wa.close();
						_openw.showded=true;
						s||_openw.show(a,null,function(){
							_openw=null;//避免快速点击打开多个页面
						});
						s&&(_openw=null);//避免s模式下变量无法重置
			//		},10);
					},false);
					_openw.addEventListener('hide',function(){
						_openw&&(_openw.showded=true);
						_openw=null;
					},false);
					_openw.addEventListener('close',function(){//页面关闭后可再次打开
						_openw=null;
						preate[id]&&(preate[id]=null);//兼容窗口的关闭
					},false);
				}
			}
			
			function scaned(t, r, f){
				var d = new Date();
				var h=d.getHours(),m=d.getMinutes(),s=d.getSeconds(),ms=d.getMilliseconds();
				if(h < 10){ h='0'+h; }
				if(m < 10){ m='0'+m; }
				if(s < 10){ s='0'+s; }
				if(ms < 10){ ms='00'+ms; }
				else if(ms < 100){ ms='0'+ms; }
				var ts = '['+h+':'+m+':'+s+'.'+ms+']';
				var li=null,hl = document.getElementById('history');
				if(blist.length > 0){
					li = document.createElement('li');
					li.className = 'ditem';
					hl.insertBefore(li, hl.childNodes[0]);
				} else{
					li = document.getElementById('nohistory');
				}
				li.id = blist.length;
				var html = '['+h+':'+m+':'+s+'.'+ms+']'+'　　'+t+'码<div class="hdata">';
				html += r;
				html += '</div>';
				li.innerHTML = html;
				li.setAttribute('onclick', 'selected(id)');
				blist[blist.length] = {type:t,result:r,file:f};
				update(t, r, f);
			}
			function selected(id){
				var h = blist[id];
				update( h.type, h.result, h.file );
				if(h.result.indexOf('http://')==0  || h.result.indexOf('https://')==0){
					plus.nativeUI.confirm(h.result, function(i){
						if(i.index == 0){
							plus.runtime.openURL(h.result);
						}
					}, '', ['打开', '取消']);
				} else{
					plus.nativeUI.alert(h.result);
				}
			}
			function update(t, r, f){
				outSet('扫描成功：');
				outLine(t);
				outLine(r);
				outLine('\n图片地址：'+f);
				if(!f || f=='null'){
					img.src = '../images/barcode.png';
				} else{
					plus.io.resolveLocalFileSystemURL(f, function(entry){
						img.src=entry.toLocalURL();
					});
					//img.src = 'http://localhost:13131/'+f;
				}
			}
			function onempty(){
				if(window.plus){
					plus.nativeUI.alert('无扫描记录');
				} else {
					alert('无扫描记录');
				}
			}
			function cleanHistroy(){
				if(blist.length > 0){
					var hl = document.getElementById('history');
					hl.innerHTML = '<li id="nohistory" class="ditem" onclick="onempty();">无历史记录	</li>';
				}
				plus.io.resolveLocalFileSystemURL('_doc/barcode/', function(entry){
					entry.removeRecursively(function(){
						// Success
					}, function(e){
						//alert( "failed"+e.message );
					});
				});
			}
		</script>
		<link rel="stylesheet" href="../../css/h5common.css" type="text/css" charset="utf-8"/>
		<link href="../../css/mui.min.css" rel="stylesheet"/>
		<style type="text/css" media="screen">
.hdata {
	color: #e1673e;	
	font-size: 14px;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

		</style>
	</head>
	<body onload="img=document.getElementById('bimg')">
		
		<header class="mui-bar mui-bar-nav">
		
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left" id="back-btn"></a>
			<div>
				<h1 class="mui-title">新增故障</h1>
			</div>
		</header>
		
		<div id="dcontent" class="dcontent">
			<br/>
			<img style="width:40%" id="bimg" src="../../images/barcode.png"/>
			<br/>
			<div class="button" onclick="clicked('barcode_scan.html',true,true)">扫一扫</div>
			<br/>
			<ul id="history" class="dlist" style="text-align:left;">
				<li id="nohistory" class="ditem" onclick="onempty()">无历史记录	</li>
			</ul>
			<br/>
			<div class="button button-waring" onclick="cleanHistroy()">清空历史记录</div>
		</div>
	</body>
	<script type="text/javascript" src="../../js/immersed.js" ></script>
	<script src="../../js/mui.min.js"></script>
	<script>
		var backBtn = document.getElementById("back-btn");
		backBtn.addEventListener("tap", function() {
			mui.back();
		}, false);
	</script>
</html>